package naito_rescue.communication.channel;

import sample.*;
import rescuecore2.messages.*;
import rescuecore2.worldmodel.*;
import rescuecore2.Constants;
import rescuecore2.config.*;
import rescuecore2.standard.components.*;
import rescuecore2.standard.entities.*;
import rescuecore2.standard.messages.*;
import rescuecore2.misc.geometry.*;

import naito_rescue.*;
import naito_rescue.agent.*;
import naito_rescue.object.*;
import naito_rescue.message.*;
import naito_rescue.message.manager.*;

public abstract class AbstractChannel
{
	protected int channelNumber;
	protected int bandwidth;
	protected double inputDropoutProb; //未実装
	protected double inputFailureProb;
	protected double outputDropoutProb;
	protected double outputFailureProb; //未実装
	protected int    previousUsedTime;
	protected int    previousUsedBandwidth;

	public AbstractChannel(int num, int bw, double inputFailureProb, double outputDropoutProb){
		this.channelNumber = num;
		this.bandwidth = bw;
		this.inputFailureProb = inputFailureProb;
		this.outputDropoutProb = outputDropoutProb;
		this.previousUsedTime = 0;
	}
	
	public int getChannelNum(){
		return channelNumber;
	}
	public int getBandwidth(){
		return bandwidth;
	}
	public double getInputFailureProb(){
		return inputFailureProb;
	}
	public double getOutputDropoutProb(){
		return outputDropoutProb;
	}
	
	@Override
	public boolean equals(Object other){
		if(other instanceof AbstractChannel){
			AbstractChannel otherChannel = (AbstractChannel)other;
			return otherChannel.getChannelNum() == this.getChannelNum();
		}
		return false;
	}
	@Override
	public int hashCode(){
		return getChannelNum() * 31;
	}
	@Override
	public String toString(){
		StringBuffer sb = new StringBuffer();
		String type = ((this instanceof RadioChannel)?"[Radio(":"[Voice(");
		sb.append(type);
		sb.append(this.getChannelNum() + "):");
		sb.append("Bandwidth=" + this.getBandwidth() + "]");
		return sb.toString();
	}
	
	public int remainderBandwidth(int time){
		if(time != this.previousUsedTime){
			this.previousUsedBandwidth = this.bandwidth;
		}
		return this.previousUsedBandwidth;
	}
	public void setUsedBandwidth(int time, int used){
		this.previousUsedBandwidth -= used;
	}
}
